import math

def rad(d):
        return d * 3.1415926535898 / 180.0

def ang(r):
        return r * 180.0 / 3.1415926535898

class Distance:
        def __init__(self):
                self.EARTH_RADIUS = 6378137


        def getDistance(self, lat1, lng1, lat2, lng2):
                a = rad(lat1) - rad(lat2)
                b = rad(lng1) - rad(lng2)
                c = math.sin(a/2) ** 2
                d = math.cos(rad(lat1)) * math.cos(rad(lat2))
                e = math.sin(b/2) ** 2
                f = math.sqrt(c + d * e)
                s = 2 * math.asin(f)
                s = s * self.EARTH_RADIUS
                return s

        def getSphere(self, lat, lng, dist):
                s = float(dist)
                s /= self.EARTH_RADIUS
                f = math.sin(s/2)

                Y = math.asin(f)
                X1 = rad(lat) - 2* Y
                X2 = rad(lat) + 2* Y
                S = ang(X1)
                N = ang(X2)

                d = math.cos(lat) ** 2
                Z = math.sqrt( f ** 2/ d )
                Y = math.asin(Z) * 2
                X1 = rad(lng) -  Y
                X2 = rad(lng) +  Y
                W = ang(X1)
                E = ang(X2)

                return (S, N, W, E)
